package com.gzhryc.shared_device.oem.code.statistics.dao;

import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.DateBranchTableDao;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.statistics.dao.db.CityAreaDayStatistics;
import com.gzhryc.shared_device.oem.code.statistics.dao.models.ProvinceSumMoneyData;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class CityAreaDayStatisticsDao extends DateBranchTableDao<CityAreaDayStatistics> {

    public CityAreaDayStatisticsDao(String jdbcKey) {
        super(jdbcKey, new Date());
    }

    public CityAreaDayStatisticsDao(String jdbcKey, Date date) {
        super(jdbcKey, date);
    }

    public List<ProvinceSumMoneyData> sumMoneyGroupProvince(Conditions conditions) throws SQLException {
        String sql = "SELECT province,SUM(order_count) AS orderCount,SUM(order_money) AS orderMoney" +
                ",SUM(order_pay_money) AS orderPayMoney,SUM(history_cancel_order_count) AS cancelOrderCount" +
                ",SUM(history_cancel_order_money) AS cancelOrderMoney,SUM(history_refund_order_count) AS refundOrderCount" +
                ",SUM(history_refund_order_money) AS refundOrderMoney FROM " + this.tableName;

        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.appendSql(" GROUP BY province");
        return this.jdbcHelper.find(query,ProvinceSumMoneyData.class);
    }
}
